//
//  myFavoriteVC.m
//  phmall
//
//  Created by admin on 2017/10/24.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "MyFavoriteVC.h"
#import "Orderheader.h"
#import "FavoriteGoodsView.h"
#import "FavoriteStoreView.h"
@interface MyFavoriteVC ()<UIScrollViewDelegate>{
    Orderheader *_headView;
    UIScrollView *_scrollView;
    FavoriteGoodsView *favoriteGoods;
    FavoriteStoreView *favoriteStore;
}
@end

@implementation MyFavoriteVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navBarBgAlpha=@"1.0";
    // 改变NavBar顶层View的颜色
    self.navigationController.navigationBar.barTintColor =  [UIColor whiteColor];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=Localized(@"我的收藏");
 
    UIBarButtonItem* leftBar=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarAction)];
    self.navigationItem.leftBarButtonItem=leftBar;
    [self setUI];
//    [self loadNewShop];
    
    
    // Do any additional setup after loading the view.
}
-(void)setUI{
 
    //消除强引用
    __weak typeof(self) weakSelf = self;
    _headView = [[Orderheader alloc]init];
    [self.view addSubview:_headView];
    [_headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(0);
        make.left.right.equalTo(self.view);
        make.height.offset(40);
    }];
    _headView.backgroundColor=[UIColor colorWithHexString:@"#f8fafd"];
    _headView.itemClickAtIndex = ^(NSInteger index){
        [weakSelf adjustScrollView:index];
    };
    _headView.items = @[Localized(@"收藏商品"),Localized(@"收藏店铺")];
    
    _scrollView = [[UIScrollView alloc]init];
    _scrollView.bounces = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    _scrollView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    
    _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH*_headView.items.count, SCREEN_HEIGHT-40-(STATUS_BAR_HEIGHT+44));
    //
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_headView.mas_bottom);
        make.left.right.equalTo(self.view);
        make.bottom.bottom.equalTo(self.view).with.offset(-self.tabBar_height);
    }];
    [_scrollView.superview layoutIfNeeded];
    
    favoriteGoods=[[FavoriteGoodsView alloc]init];
    favoriteGoods.backgroundColor=[UIColor whiteColor];
    [_scrollView addSubview:favoriteGoods];
    
    [favoriteGoods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_scrollView);
        make.left.equalTo(_scrollView).with.offset(0);
        make.height.offset(SCREEN_HEIGHT-40-(STATUS_BAR_HEIGHT+44)-self.tabBar_height);
        make.width.offset(SCREEN_WIDTH);
    }];
    
    favoriteStore=[[FavoriteStoreView alloc]init];
    favoriteStore.backgroundColor=[UIColor whiteColor];
    [_scrollView addSubview:favoriteStore];
    
    [favoriteStore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_scrollView);
        make.left.equalTo(_scrollView).with.offset(SCREEN_WIDTH);
        make.height.offset(SCREEN_HEIGHT-40-(STATUS_BAR_HEIGHT+44)-self.tabBar_height);
        make.width.offset(SCREEN_WIDTH);
    }];
}
#pragma mark-通过点击button来改变scrollview的偏移量
-(void)adjustScrollView:(NSInteger)index
{
    [UIView animateWithDuration:0.2 animations:^{
        _scrollView.contentOffset = CGPointMake(index*_scrollView.bounds.size.width, 0);
    }];
}

#pragma mark-选中scorllview来调整headvie的选中
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger index = scrollView.contentOffset.x/scrollView.bounds.size.width;
    [_headView setSelectAtIndex:index];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
